<?php
session_start();
include "../../inc/logging.php";
include "../../inc/inc.koneksi.php";
include "../../inc/fungsi_tanggal.php";
$table		="spp";
$tgl		=jin_date_sql($_POST['tgl']);
$no		=$_POST['no'];
$jenis		=$_POST['jenis'];
$jml		=$_POST['jml'];
$edit		=$_POST['edit'];

$strQueryCekSpp = '';
$strQueryCekSpp .= 'SELECT * FROM ' . $table . ' WHERE id_jenis = ' . $jenis . ' AND noinduk = "' . $no . '"';
note('QUERY CHECK: ' . $strQueryCekSpp);

$sql = mysql_query($strQueryCekSpp);

note('ROWS: ' . mysql_num_rows($sql));
note('EDIT: ' . $edit);

if ($edit == 'true') {

    mysql_query('UPDATE ' . $table . ' SET tgl = "' . $tgl . '", jumlah = ' . $jml . ' WHERE id_jenis = ' . $jenis . ' AND noinduk = "' . $no . '"');
    echo "Data berhasil diubah";

} else {
    
    if (mysql_num_rows($sql) > 0) {
        echo 'Data SPP sudah ada';

    } else {

        $input = "INSERT INTO $table (tgl,noinduk,id_jenis,jumlah) VALUES('$tgl','$no','$jenis','$jml')";
        mysql_query($input);
        echo "Data berhasil disimpan";
    }
    
}

?>